// pages/gongmu/index_gm/index_gm.js
import request from '../../utils/http.js'
const app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        shopIsChange: false,
        screenWidth: 0,
        screenHeight: 0,
        IsLogin: false,
        code: '',
        tjr_id: 0,
        dianPuId: 0,
        peiZhenPersonId: 0,
        isEmpty: true,
        hiddenPopPaper: false,
        isSearchFlag: false,
        searchCardNum: '',
        recordList: [],
        name: '',
        sex: '',
        guid: '',
        currentTab: 0, //预设当前项的值
        verIndex: 2,
        city: '',
        typeIndex: 0, //业务类型 1.陪诊 2.找专家医生 3.找特需专家 4.住院
        cityCode: '',
        fenZuList: '',
        lBImgUrl: '',
        lBVidoUrl: 'https://insurancecard.oneplusyang.com/2023060915492474d7a2fb922f4855942bca1d0e6d3db1.mp4',
        lBImgUrl: 'https://insurancecard.oneplusyang.com/20230609160457a602457025094bef8b13496277f24e2f.png',
        autaPlay: false,
        doctor: [],
        isShowZhiBo: true, //是否显示直播
        roomId: 0,
        type: 0, // 可选 
        closePictureInPictureMode: 0,
        customParams: '',
        mingCheng: '',
        logoImg: '',
        diZhi: '',
        dianPuId: 0,
        dianPuLeiXing: '',
        dianPuLeiXingStr: '',
        dianPuBianHao: '',
        danganqhList: [],
        updateDate: '',
        rzstat: '', //是否认证
        zyysSign: '', //24小时
        chanPinId: 0,
        xy_zhuangTai: 0,
        xy: 0,
        xd_zhuangTai: 0,
        xd: 0,
        tw_zhuangTai: 0,
        tw: 0,
        indexs: 0,
        selectedIndex: 0, // 初始时未选中任何档案
        currentTab: 0,
        tabList: ["健康档案", "就医服务"],
        adList: [],
        wugengTitle: '',
        wuGengList: [],
        articleList: [],
        indicatorDots: true,
        vertical: false,
        autoplay: true,
        interval: 3000,
        duration: 500,
        isYuyue: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        wx.getSystemInfo({
            success: function (res) {
                that.setData({
                    screenWidth: res.screenWidth - 92,
                    screenHeight: res.screenHeight - app.globalData.CustomBar,
                });
            }
        });
        that.setData({
            IsLogin: options.dianPuId > 0 ? false : wx.getStorageSync(app.globalData.LOGINSTATUS),
            dianPuId: (options.dianPuId == '' || options.dianPuId == undefined) ? (wx.getStorageSync(app.globalData.SHOPID) > 0 ? wx.getStorageSync(app.globalData.SHOPID) : 1) : options.dianPuId,
            tjr_id: (options.tjr_id == '' || options.tjr_id == undefined) ? wx.getStorageSync(app.globalData.TJR_ID) : options.tjr_id,
            personId: wx.getStorageSync(app.globalData.PERSON_ID),
            verIndex: wx.getStorageSync(app.globalData.VerIndex),
        })
        if (options.scene) { //海报扫码
            let scene = decodeURIComponent(options.scene);
            that.setData({
                IsLogin: false,
                dianPuId: scene.split("_")[0],
                tjr_id: scene.split("_")[1],
            })
        }
        wx.setStorageSync(app.globalData.SHOPID, that.data.dianPuId)
        wx.setStorageSync(app.globalData.TJR_ID, that.data.tjr_id)
        wx.setStorageSync(app.globalData.LOGINSTATUS, that.data.IsLogin)
        that.getShoppingInfo();
        that.getVersion();
        if (that.data.city == '' && that.data.cityCode == '') {
            that.getCityList();
        }
        that.yiShengList();
        that.getIndexId();
        that.getAdList()
        that.getWuGengList()
        this.getArticleList()
        this.getXcxVersion()
        wx.login({
            success: res => {
                that.setData({
                    code: res.code
                })
            }
        })
    },

    showToast: function (){
        wx.showToast({
            title: '功能开发中！', // 提示的内容
            icon: "none", // 图标，默认success
            duration: 3000, // 提示的延迟时间，默认1500
            mask: false, // 是否显示透明蒙层，防止触摸穿透
          })
    },

    // 获取轮播图
    getAdList: function () {
        let that = this
        request.get('jianKangZhiNan/lunBoTu', null, res => {
            that.setData({
                adList: res.data
            })
        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })
    },

    bindAdChange: function (e) {
        let path = e.currentTarget.dataset.path;
        path && wx.navigateTo({
            url: path + '&personId=' + this.data.personId + '&tjr_id=' + this.data.tjr_id,
        })
    },

    // 获取资讯列表
    getArticleList: function () {
        let that = this
        request.get('v2new/getIndexThreeDetails', null, res => {
            that.setData({
                articleList: res.data.data
            })
        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })
    },

    // 获取无梗中国秘方
    getWuGengList: function () {
        let that = this
        let data = {
            version: app.globalData.version
        }
        request.get('v2new/getWuGengMiFang', data, res => {
            let data = res.data.data
            that.setData({
                wugengTitle: data.biaoti
            })
            let list = data.neirong
            list.forEach(item => {
                that.getProjectInfo(item)
            })
        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })
    },
    // 根据产品id获取信息
    getProjectInfo: function (item) {
        let that = this
        let list = that.data.wuGengList
        request.get('product/getWugengProudct', {
            productId: item.chanPinId
        }, res => {
            let data = Object.assign({}, item, res.data)
            list.push(data)
            that.setData({
                wuGengList: list
            })
        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })
    },

    //产品详情页
    toProductInfo: function (e) {
        var productId = e.currentTarget.dataset.id;
        var type = e.currentTarget.dataset.c;
        app.globalData.tabIndex = this.data.currentTab
        if (type == 2) {
            wx.navigateTo({
                url: '/pages/product_info_fwb/product_info_fwb?productId=' + productId + '&personId=' + this.data.personId + '&tjr_id=' + this.data.tjr_id,
            })
        } else {
            wx.navigateTo({
                url: '/pages/product_info/product_info?productId=' + productId + '&personId=' + this.data.personId + '&tjr_id=' + this.data.tjr_id,
            })
        }
    },

    getXcxVersion: function () {
        let that = this
        let data = {
            version: app.globalData.version
        }
        request.get('v2new/getXcxVersion', data, res => {
            let code = res.data.code
            that.setData({
                isYuyue: code == 200 ? true : false
            })
        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })
    },

    bindYuyue: function () {
        // if (!this.data.isYuyue) {
        //     this.showToast()
        //     return
        // }
        wx.navigateTo({
            url: '/pages/yuyue/index',
        })
    },

    toHomeNavigate: function (e) {
        let type = e.currentTarget.dataset.type;
        switch (type) {
            case '0':
                wx.navigateTo({
                    url: '/pages/about/index',
                })
                break;
            case '1':
                wx.setStorageSync('categoryId', 26)
                wx.switchTab({
                    url: '/pages/shop/shop',
                })
                break;
            case '2':
                wx.showToast({
                    title: '功能开发中！', // 提示的内容
                    icon: "none", // 图标，默认success
                    duration: 3000, // 提示的延迟时间，默认1500
                    mask: false, // 是否显示透明蒙层，防止触摸穿透
                })
                break;
            case '3':
                wx.switchTab({
                    url: '/pages/shop/shop',
                })
                break;
            case '4':
                wx.switchTab({
                    url: '/pages/zhuanbing/index',
                })
                break;
        }
    },

    //获取陪诊开通的城市 
    getCityList: function () {
        var that = this
        let data = {}
        request.get('peiZhenProduct/getCityList', null, res => {
            // console.log("获取陪诊开通的城市 :" + JSON.stringify(res.data))
            that.setData({
                cityCode: res.data.defaultCityCode,
                city: res.data.defaultCityName
            })
        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })

    },

    //获取陪诊产品
    getPeiZhenList: function () {
        var that = this
        let data = {
            cityCode: that.data.cityCode
        }
        request.get('peiZhenProduct/getPeiZhenList', data, res => {
            // console.log("获取陪诊产品:" + JSON.stringify(res.data))
            that.setData({
                fenZuList: res.data.fenZuList
            })
        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })

    },


    //获取医师list
    yiShengList: function () {
        var that = this
        request.get('yiSheng/yiShengList', null, res => {
            //  console.log("获取医师list:" + JSON.stringify(res.data))
            that.setData({
                doctor: res.data.list,
            })
        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })

    },

    //获取店铺信息
    getShoppingInfo: function () {
        var that = this
        let data = {
            dianPuId: that.data.dianPuId
        }
        request.get('dianPu/basicInfo', data, res => {
            console.log("店铺信息:" + JSON.stringify(res.data))
            that.setData({
                mingCheng: res.data.mingCheng,
                logoImg: res.data.logo,
                diZhi: res.data.diZhi,
                dianPuId: res.data.dianPuId,
                dianPuLeiXing: res.data.dianPuLeiXing,
                dianPuLeiXingStr: res.data.dianPuLeiXingStr,
                dianPuBianHao: res.data.dianPuBianHao,
            })

            wx.setStorageSync(app.globalData.SHOPID, res.data.dianPuId)
            wx.setStorageSync(app.globalData.ShopName, res.data.mingCheng);
            wx.setStorageSync(app.globalData.ShopLogo, res.data.logo);
            wx.setStorageSync(app.globalData.JKQName, res.data.jianKangQuanMingCheng)

        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })

    },


    //获取查询手机号
    bindSearchInput: function (e) {
        this.setData({
            searchCardNum: e.detail.value
        })
    },

    //页签切换
    changeTab(e) {
        var index = e.currentTarget.dataset.index
        // console.log(index)
        this.setData({
            currentTab: index
        })
    },

    //根据token转换手机号查询档案
    searchByPhone: function () {

        // wx.showLoading({
        //   title: '加载中...',
        //   mask: true
        // })

        var that = this
        let data = {
            shenFenZhenHao: ''
        }
        request.get('jianKangDangAn/jiuZhenRenListFromYiJiaYi', data, res => {
            // console.log("根据手机号查询:" + JSON.stringify(res.data))
            wx.hideLoading()
            if (res.data.status != 401 && res.data.status != 500 && res.data.list.length > 0) {
                that.setData({
                    recordList: res.data.list,
                    updateDate: res.data.list[0].updateDate,
                    rzstat: res.data.list[0].danganlist.rzstat,
                    zyysSign: res.data.list[0].danganlist.zyysSign,
                    chanPinId: res.data.list[0].danganlist.chanPinId,
                    xy_zhuangTai: res.data.list[0].danganlist.xy_zhuangTai,
                    xy: res.data.list[0].danganlist.xy == null || res.data.list[0].danganlist.xy == '' ? '--' : res.data.list[0].danganlist.xy,
                    xd_zhuangTai: res.data.list[0].danganlist.xd_zhuangTai,
                    xd: res.data.list[0].danganlist.xd == null || res.data.list[0].danganlist.xd == '' ? '--' : res.data.list[0].danganlist.xd,
                    tw_zhuangTai: res.data.list[0].danganlist.tw_zhuangTai,
                    tw: res.data.list[0].danganlist.tw == null || res.data.list[0].danganlist.tw == '' ? '--' : res.data.list[0].danganlist.tw,
                    guid: res.data.list[0].danganlist.guid,
                    isEmpty: res.data.list.length > 0 ? false : true
                })
            }
        }, err => {
            wx.hideLoading()
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })

    },

    qhdangan_tap: function (e) {
        var index = e.currentTarget.dataset.index
        this.setData({
            selectedIndex: index
        });
        this.setData({
            indexs: index,
            danganqhList: this.data.recordList[index].danganlist,
            updateDate: this.data.recordList[index].danganlist.updateDate,
            rzstat: this.data.recordList[index].danganlist.rzstat,
            zyysSign: this.data.recordList[index].danganlist.zyysSign,
            chanPinId: this.data.recordList[index].danganlist.chanPinId,
            xy_zhuangTai: this.data.recordList[index].danganlist.xy_zhuangTai,
            xy: this.data.recordList[index].danganlist.xy == null || this.data.recordList[index].danganlist.xy == '' ? '--' : this.data.recordList[index].danganlist.xy,
            xd_zhuangTai: this.data.recordList[index].danganlist.xd_zhuangTai,
            xd: this.data.recordList[index].danganlist.xd == null || this.data.recordList[index].danganlist.xd == '' ? '--' : this.data.recordList[index].danganlist.xd,
            tw_zhuangTai: this.data.recordList[index].danganlist.tw_zhuangTai,
            tw: this.data.recordList[index].danganlist.tw == null || this.data.recordList[index].danganlist.tw == '' ? '--' : this.data.recordList[index].danganlist.tw,
            guid: this.data.recordList[index].danganlist.guid,
        })
    },


    //添加健康档案
    addOneRecord: function () {

        var that = this

        let data = {
            shenFenZhengHao: that.data.searchCardNum
        }
        request.get('jianKangDangAn/addOneJiuZhenRen', data, res => {
            // console.log("添加档案:" + JSON.stringify(res.data))

            if (res.data.status == 1) {
                that.closeAction();
                that.searchByPhone();
            } else {
                wx.showToast({
                    title: '添加失败！', // 提示的内容
                    icon: "none", // 图标，默认success
                    duration: 1000, // 提示的延迟时间，默认1500
                    mask: false, // 是否显示透明蒙层，防止触摸穿透
                })
            }

        }, err => {
            wx.showToast({
                title: '获取信息失败', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        })

    },

    //激活会员
    jihuoAction: function () {
        var that = this
        if (that.data.guid != '' && that.data.searchCardNum != '') {
            let data = {
                jiHuoMa: that.data.searchCardNum,
                guid: that.data.guid
            }
            request.get('qiTa/jiHuoHuiYuanKa', data, res => {
                // console.log("添加档案:" + JSON.stringify(res.data))

                if (res.data.status == 1) {
                    that.closeAction();
                    that.searchByPhone();
                } else {
                    wx.showToast({
                        title: '激活失败，请确认激活码是否有效！', // 提示的内容
                        icon: "none", // 图标，默认success
                        duration: 3000, // 提示的延迟时间，默认1500
                        mask: false, // 是否显示透明蒙层，防止触摸穿透
                    })
                }

            }, err => {
                wx.showToast({
                    title: '获取信息失败', // 提示的内容
                    icon: "none", // 图标，默认success
                    duration: 1000, // 提示的延迟时间，默认1500
                    mask: false, // 是否显示透明蒙层，防止触摸穿透
                })
            })
        } else {
            wx.showToast({
                title: '请输入激活码', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        }


    },

    //显示查询弹窗
    showSearch: function (e) {
        var index = e.currentTarget.dataset.index
        console.log(index)
        if (this.data.IsLogin) {
            this.setData({
                hiddenPopPaper: true,
                name: this.data.recordList[index].danganlist.name,
                sex: this.data.recordList[index].danganlist.sex,
                guid: this.data.recordList[index].danganlist.guid,
            })
        } else {
            wx.showToast({
                title: '请您登录', // 提示的内容
                icon: "none", // 图标，默认success
                duration: 1000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        }
    },

    //关闭查询弹窗
    closeAction: function () {
        this.setData({
            hiddenPopPaper: false,
            isSearchFlag: false,
            searchCardNum: '',
            name: '',
            sex: '',
            guid: ''
        })
    },


    //健康档案详情
    toHealthData: function (e) {
        var guid = this.data.recordList[this.data.selectedIndex].danganlist.guid
        console.log("档案guid：" + guid)
        if (guid == 'undefined' || guid == undefined || guid == '' || guid == null) {
            wx.showToast({
                title: "档案人员ID不正常", // 提示的内容
                icon: "none", // 图标，默认success
                duration: 3000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        } else {
            wx.navigateTo({
                url: '/pkg_index/pages/healthData/healthData?guid=' + guid,
            })
        }

    },


    //获取陪诊系统店主ID
    getPeiZhenTjrID() {
        var that = this
        wx.request({
            url: app.globalData.base_url + 'login/getPeiZhenTuiGuangYuanId',
            data: {
                dianPuId: that.data.dianPuId,
            },
            success: function (res) {
                // console.log("陪诊推荐人ID:" + JSON.stringify(res.data))
                that.setData({
                    peiZhenPersonId: res.data.peiZhenPersonId
                })
            },
        })
    },

    //点击进入陪诊系统
    toPeiZhen() {
        wx.navigateToMiniProgram({
            appId: 'wx7b831f4895d381d6',
            path: 'pages/index/index?tjrId=' + this.data.peiZhenPersonId + '&dianPuId=' + this.data.dianPuId,
            extraData: {},
            envVersion: 'release',
            success(res) {
                // 打开成功
            }
        })
    },

    //地图跳转
    toMapList() {
        console.log("aaaaa")
        wx.navigateTo({
            url: '/pkg_pz/pages/city/city',
        })

    },

    //跳转医师详情
    doctortap: function (e) {
        var ysid = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pkg_doctors/pages/doctor/doctor?ysid=' + ysid,
        })
    },

    //跳转医师列表
    doctorlisttap: function () {
        // if (!this.data.isYuyue) {
        //     this.showToast()
        //     return
        // }
        wx.navigateTo({
            url: '/pkg_doctors/pages/doctorlist/doctorlist',
        })
    },

    //跳转健康知识科普
    toHealthKp: function () {
        // if (!this.data.isYuyue) {
        //     this.showToast()
        //     return
        // }
        wx.navigateTo({
            url: '/pkg_doctors/pages/zhinan/index',
        })
    },

    //切换店铺
    bindSetPageTap: function () {
        if (this.data.IsLogin) {
            wx.navigateTo({
                url: '/pkg_wo/pages/setPage/setPage?personId=' + this.data.personId + '&dianPuId=' + this.data.dianPuId,
            })
        } else {
            wx.switchTab({
                url: '/pages/personal/personal'
            })
        }
    },
    // 详情
    toArticleDetail: function (e) {
        let item = e.currentTarget.dataset.item;
        wx.setStorageSync('articleInfo', item)
        wx.navigateTo({
            url: `/pages/article/detail`,
        })
    },

    //跳转陪诊页面
    toPzInfo: function (e) {
        var typeIndex = e.currentTarget.dataset.index
        var peiZhenProductId = e.currentTarget.dataset.id
        // wx.navigateTo({
        //   url: '/pkg_pz/pages/pzInfo/pzInfo?personId=' + this.data.personId + '&dianPuId=' + this.data.dianPuId,
        // })
        wx.navigateTo({
            url: '/pkg_pz/pages/pzInfo/pzInfo?dianPuId=' + this.data.dianPuId + '&peiZhenProductId=' + peiZhenProductId + '&typeIndex=' + typeIndex,
        })
    },


    //获取公共接口ID
    getIndexId: function () {
        var that = this
        let data = {
            dianPuId: that.data.dianPuId
        }
        request.get('version/getJiQiRenChanPinId', data, res => {

            console.log("直播:" + JSON.stringify(res.data))
            // let type = 0 // 0. 显示直播、预告、商品讲解、回放其中之一的挂件；1. 只显示直播的挂件；2. 只显示预告的挂件；3. 只显示商品讲解的挂件；4. 只显示回放的挂件
            // let customParams = ""// 开发者在直播间页面路径上携带自定义参数（如示例中的path和pid参数），后续可以在分享卡片链接和跳转至商详页时获取，详见【获取自定义参数】、【直播间到商详页面携带参数】章节（上限600个字符，超过部分会被截断）
            // let closePictureInPictureMode = 0 // 是否关闭小窗

            let customParams = encodeURIComponent(JSON.stringify({
                tjr_id: that.data.personId,
                dianPuId: that.data.dianPuId
            })) // 开发者在直播间页面路径上携带自定义参数（如示例中的 path 和pid参数），后续可以在分享卡片链接和跳转至商详页时获取，详见【获取自定义参数】、【直播间到商详页面携带参数】章节（上限600个字符，超过部分会被截断）
            let closePictureInPictureMode = 0 // 是否关闭小窗


            that.setData({
                type: res.data.zhiBaoLeiXing == 2 ? '4' : '0', // 0. 显示直播、预告、商品讲解、回放其中之一的挂件；1. 只显示直播的挂件；2. 只显示预告的挂件；3. 只显示商品讲解的挂件；4. 只显示回放的挂件
                roomId: res.data.zhiBaoHuiFangId,
                customParams: customParams,
                closePictureInPictureMode: closePictureInPictureMode,
                isShowZhiBo: res.data.zhiBaoZhuangTai == 1 ? false : true
            })

        }, err => {

        })

    },

    //获取审核状态
    getVersion: function () {
        var that = this
        let data = {
            version: app.globalData.version
        }
        request.get('version/getVersionStaus', data, res => {

            // console.log("getVersionStaus:" + JSON.stringify(res.data))
            wx.setStorageSync(app.globalData.VerIndex, res.data.status)
            that.setData({
                verIndex: res.data.status
            })

        }, err => {

        })
    },


    //不显示直播挂件
    closeZhiBo() {
        this.setData({
            isShowZhiBo: false
        })
    },

    //亮证
    bindClosePaper: function () {
        // this.setData({
        //   hiddenSharePaper: !this.data.hiddenSharePaper,
        // })

        wx.previewImage({
            urls: ['https://insurancecard.oneplusyang.com/202311231529255b55eecb45eb46d5afb5beddc5cb18cf.png'], //需要预览的图片http链接列表，注意是数组
            current: '', // 当前显示图片的http链接，默认是第一个
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
        })

    },

    //V3.0 获取手机号码
    getPhoneNumber: function (e) {
        var that = this
        if (e.detail.errMsg == "getPhoneNumber:ok") { //允许
            that.decryptPhone(e);
        } else { //拒绝
            wx.showToast({
                title: "请授权！！", // 提示的内容
                icon: "none", // 图标，默认success
                duration: 3000, // 提示的延迟时间，默认1500
                mask: false, // 是否显示透明蒙层，防止触摸穿透
            })
        }
    },


    //V3.0 解密手机号码
    decryptPhone: function (e) {

        wx.showLoading({
            title: '解析中...',
            mask: true
        })

        var that = this;
        let code = that.data.code;
        let iv = e.detail.iv;
        let encryptedData = e.detail.encryptedData;

        wx.request({
            url: app.globalData.base_url + 'resource/getWXPhoneDirect',
            data: {
                iv: iv,
                js_code: code,
                encrypted: encryptedData,
                tuiJianRenId: that.data.tjr_id,
                dianPuId: that.data.dianPuId
            },
            success: function (res) {
                //  console.log("解密手机号码:" + JSON.stringify(res.data))

                if (res.data.purePhoneNumber == '' || res.data.status == 500) {

                    wx.showToast({
                        title: '解析异常，右上角重新进入小程序', // 提示的内容
                        icon: "none", // 图标，默认success
                        duration: 3000, // 提示的延迟时间，默认1500
                        mask: false, // 是否显示透明蒙层，防止触摸穿透
                    })

                } else {
                    wx.setStorageSync(app.globalData.OPENID, res.data.openId)
                    wx.setStorageSync(app.globalData.PERSON_ID, res.data.personId)
                    wx.setStorageSync(app.globalData.TOKEN, res.data.token)
                    wx.setStorageSync(app.globalData.PHONENUMBER, res.data.purePhoneNumber)
                    wx.setStorageSync(app.globalData.LOGINSTATUS, true)
                    wx.setStorageSync(app.globalData.NiCheng, res.data.niCheng)
                    wx.setStorageSync(app.globalData.TouXiang, res.data.touXiangUrl)

                    that.syncData(res.data.token)
                    that.setData({
                        IsLogin: true
                    })
                    // that.gouMaibind()
                    that.searchByPhone();

                }


            },
            fail: function (err) {
                that.setData({
                    IsLogin: false
                })
                wx.showToast({
                    title: '获取数据失败,请检查网络', // 提示的内容
                    icon: "none", // 图标，默认success
                    duration: 3000, // 提示的延迟时间，默认1500
                    mask: false, // 是否显示透明蒙层，防止触摸穿透
                })
            },
            complete: function (res) {
                wx.hideLoading();
            }
        })
    },


    //登录同步健康数据
    syncData(token) {

        wx.request({
            url: app.globalData.base_url + 'qiTa/tongBuJiuZhenRenAndGouMaiChanPin',
            header: {
                'token': token,
            },
            success: function (res) {
                console.log("同步数据成功")
            },
            fail: function (err) {
                console.log("同步数据失败")
            },
            complete: function (res) {
                console.log("同步数据完成")

            }
        })


    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

        if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            this.getTabBar().setData({
                selected: 0
            })
        }

        if (app.globalData.shopIsChange) {
            this.setData({
                dianPuId: wx.getStorageSync(app.globalData.SHOPID)
            })
            this.getShoppingInfo();
        }



        this.getPeiZhenList();
        this.setData({
            IsLogin: wx.getStorageSync(app.globalData.LOGINSTATUS),
        })
        if (this.data.IsLogin) {
            this.setData({
                selectedIndex: 0
            })
            this.searchByPhone();
        }
    },

    //分组切换
    onTabsChange(e) {
        let index = e.detail.current == undefined ? e.detail.value : e.detail.current
        if (this.data.currentTab == index) {
            return false;
        } else {
            this.setData({
                currentTab: index
            })
        }
    },


    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})